class Song {
  final String songId;
  final String title;
  final String artist;
  final String downloadUrl;
  bool isDownloaded;
  String? localPath;
  String? lyrics;
  bool isDownloading;
  bool isHot;

  Song({
    required this.songId,
    required this.title,
    required this.artist,
    required this.downloadUrl,
    this.isDownloaded = false,
    this.localPath,
    this.lyrics,
    this.isDownloading = false,
    this.isHot = false,
  });

  Map<String, dynamic> toMap() {
    return {
      'songId': songId,
      'title': title,
      'artist': artist,
      'downloadUrl': downloadUrl,
      'isDownloaded': isDownloaded ? 1 : 0,
      'localPath': localPath,
      'lyrics': lyrics,
      'isDownloading': isDownloading ? 1 : 0,
      'isHot': isHot ? 1 : 0,
    };
  }

  factory Song.fromMap(Map<String, dynamic> map) {
    return Song(
      songId: map['songId'],
      title: map['title'],
      artist: map['artist'],
      downloadUrl: map['downloadUrl'],
      isDownloaded: map['isDownloaded'] == 1,
      localPath: map['localPath'],
      lyrics: map['lyrics'],
      isDownloading: map['isDownloading'] == 1,
      isHot: map['hot'] == 1,
    );
  }

  Song copyWith({
    String? songId,
    String? title,
    String? artist,
    String? downloadUrl,
    bool? isDownloaded,
    String? localPath,
    String? lyrics,
    bool? isDownloading,
    bool? isHot,
  }) {
    return Song(
      songId: songId ?? this.songId,
      title: title ?? this.title,
      artist: artist ?? this.artist,
      downloadUrl: downloadUrl ?? this.downloadUrl,
      isDownloaded: isDownloaded ?? this.isDownloaded,
      localPath: localPath ?? this.localPath,
      lyrics: lyrics ?? this.lyrics,
      isDownloading: isDownloading ?? this.isDownloading,
      isHot: isHot ?? this.isHot,
    );
  }

  factory Song.fromJson(Map<String, dynamic> json) {
    return Song(
      songId: json['id'],
      title: json['title'],
      artist: json['artist'],
      downloadUrl: json['downloadUrl'],
      isDownloaded: json['isDownloaded'] ?? false,
      isHot: json['isHot'] ?? false,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': songId,
      'title': title,
      'artist': artist,
      'downloadUrl': downloadUrl,
      'isDownloaded': isDownloaded,
      'isHot': isHot,
    };
  }
}
